<?xml version="1.0" encoding="UTF-8"?>
<ui:composition xmlns="http://www.w3.org/1999/xhtml" xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core" xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:p="http://primefaces.org/ui"
	template="/templates/template.xhtml">

	<f:metadata>
		<f:event type="preRenderView" listener="#{animalBean.verificarAcesso}" />
	</f:metadata>

	<ui:define name="body">
		<h:form id="form" prependId="false">
			<p:fieldset legend="#{animalBean.qualifiedName}" id="fieldPrincipal">

				<h:panelGrid columns="4" id="panelCadastro" border="1" columnClasses="coluna15,coluna45,coluna20,coluna30"
					width="100%">

					<h:outputLabel value="Código:" />
					<p:inputText value="#{animalBean.model.codigo}" id="cod" size="5" maxlength="5" />
					<p:message for="cod" />
					<h:outputText value=" " />

					<h:outputLabel value="Nome:" styleClass="icoObrigatorio" />
					<p:inputText value="#{animalBean.model.nome}" id="nome" size="50" maxlength="255"
						requiredMessage="#{animalBean.requiredMessage}" required="true" />
					<p:message for="nome" />
					<h:outputText value=" " />

					<h:outputLabel value="Idade:" styleClass="icoObrigatorio" />
					<p:inputMask mask="9?99" value="#{animalBean.model.idade}" id="idade" size="5" maxlength="5"
						requiredMessage="#{animalBean.requiredMessage}" required="true" />
					<p:message for="idade" />
					<h:outputText value=" " />

					<h:outputLabel value="Sexo" styleClass="icoObrigatorio" />
					<p:selectOneRadio id="optionsSexo" value="#{animalBean.model.sexo}" requiredMessage="#{animalBean.requiredMessage}"
						required="true">
						<f:selectItem itemLabel="Macho" itemValue="M" />
						<f:selectItem itemLabel="Fêmea" itemValue="F" />
						<p:ajax event="change" process="optionsSexo" update="qtdParto,qtdAborto,idTipoAnimal"
							listener="#{animalBean.filtroSexo}" />
					</p:selectOneRadio>
					<p:message for="optionsSexo" />
					<h:outputText value=" " />

					<h:outputLabel value="Quantidade Parto:" />
					<p:spinner value="#{animalBean.model.qtdParto}" disabled="#{!animalBean.femea}" id="qtdParto" stepFactor="1" />
					<p:message for="qtdParto" />
					<h:outputText value=" " />

					<h:outputLabel value="Quantidade Aborto:" />
					<p:spinner value="#{animalBean.model.qtdAborto}" disabled="#{!animalBean.femea}" id="qtdAborto" stepFactor="1" />
					<p:message for="qtdAborto" />
					<h:outputText value=" " />

					<h:outputLabel value="Proprietário:" styleClass="icoObrigatorio" />
					<p:autoComplete queryDelay="500" value="#{animalBean.proprietario}" minQueryLength="2" id="proprietario" size="50"
						completeMethod="#{animalBean.completeProprietario}" forceSelection="true" var="proprietario"
						itemLabel="#{proprietario.nome}" itemValue="#{proprietario.id}" converter="proprietarioConverter"
						requiredMessage="#{animalBean.requiredMessage}" required="true" />
					<p:message for="proprietario" />
					<h:outputText value=" " />

					<h:outputLabel value="Criador:" />
					<p:autoComplete queryDelay="500" size="50" value="#{animalBean.proprietarioCriador}" minQueryLength="2"
						id="proprietarioCriador" completeMethod="#{animalBean.completeCriador}" forceSelection="true"
						var="proprietario" itemLabel="#{proprietario.nome}" itemValue="#{proprietario.id}"
						converter="proprietarioConverter" />
					<h:outputText value=" " />
					<h:outputText value=" " />

					<h:outputLabel value="Pai:" for="pai" />
					<p:autoComplete queryDelay="500" size="50" value="#{animalBean.pai}"
						completeMethod="#{animalBean.completeAnimalPai}" var="animal" forceSelection="true" itemLabel="#{animal.nome}"
						itemValue="#{animal.id}" converter="animalConverter" multiple="false" id="pai">
						<p:column style="width:20%;text-align:center">
							<p:graphicImage value="/imagemServlet?file=#{animal.urlImagemAleatoria}" width="40" height="50"
								rendered="#{animal.urlImagemAleatoria != null and !empty animal.urlImagemAleatoria}" />
						</p:column>
						<p:column style="width:60%">
							<h:outputText value="#{animal.nome}" />
						</p:column>
						<p:column style="width:20%">
							<h:outputText value="#{animal.sexoFormat}" />
						</p:column>
					</p:autoComplete>

					<h:outputText value=" " />
					<h:outputText value=" " />

					<h:outputLabel value="Mãe:" for="mae" />
					<p:autoComplete queryDelay="500" size="50" value="#{animalBean.mae}"
						completeMethod="#{animalBean.completeAnimalMae}" var="animal" forceSelection="true" itemLabel="#{animal.nome}"
						itemValue="#{animal.id}" converter="animalConverter" multiple="false" id="mae">
						<p:column style="width:20%;text-align:center">
							<p:graphicImage value="/imagemServlet?file=#{animal.urlImagemAleatoria}" width="40" height="50"
								rendered="#{animal.urlImagemAleatoria != null and !empty animal.urlImagemAleatoria}" />
						</p:column>
						<p:column style="width:60%">
							<h:outputText value="#{animal.nome}" />
						</p:column>
						<p:column style="width:20%">
							<h:outputText value="#{animal.sexoFormat}" />
						</p:column>
					</p:autoComplete>

					<h:outputText value=" " />
					<h:outputText value=" " />


					<h:outputText value="Data de Entrada:" styleClass="icoObrigatorio" />
					<h:panelGrid columns="2" cellpadding="0" cellspacing="0">
						<p:calendar locale="pt" pattern="dd/MM/yyyy" id="dtInicio" navigator="true" maxlength="10" size="15"
							readOnlyInputText="true" value="${animalBean.model.dtEntrada}" mode="popup" showOn="button"
							requiredMessage="#{animalBean.requiredMessage}" required="true" />
						<p:commandLink process="@this" title="Limpar" update="dtInicio">
							<h:graphicImage name="icone-limpar.png" library="design/imagem" />
							<f:setPropertyActionListener target="${animalBean.model.dtEntrada}" value="" />
						</p:commandLink>
					</h:panelGrid>
					<p:message for="dtInicio" />
					<h:outputText value=" " />


					<h:outputText value="Data de Saída:" />
					<h:panelGrid columns="2" cellpadding="0" cellspacing="0">
						<p:calendar locale="pt" pattern="dd/MM/yyyy" id="dtSaida" navigator="true" maxlength="10" size="15"
							readOnlyInputText="true" value="${animalBean.model.dtSaida}" mode="popup" showOn="button" />
						<p:commandLink process="@this" title="Limpar" update="dtSaida">
							<h:graphicImage name="icone-limpar.png" library="design/imagem" />
							<f:setPropertyActionListener target="${animalBean.model.dtSaida}" value="" />
						</p:commandLink>
					</h:panelGrid>
					<h:outputText value=" " />
					<h:outputText value=" " />


					<h:outputLabel value="Pelagem:" styleClass="icoObrigatorio" />
					<p:selectOneMenu id="idPelagem" effect="fade" style="width:300px;" value="#{animalBean.idPelagem}"
						requiredMessage="#{animalBean.requiredMessage}" required="true">
						<f:selectItem itemLabel="Selecione" itemValue="" />
						<f:selectItems value="#{animalBean.listaPelagem}" />
					</p:selectOneMenu>
					<p:message for="idPelagem" />
					<h:outputText value=" " />

					<h:outputLabel value="Função do Animal:" styleClass="icoObrigatorio" />
					<p:selectOneMenu id="idFuncao" effect="fade" style="width:300px;" value="#{animalBean.idFuncaoAnimal}"
						requiredMessage="#{animalBean.requiredMessage}" required="true">
						<f:selectItem itemLabel="Selecione" itemValue="" />
						<f:selectItems value="#{animalBean.listaFuncaoAnimal}" />
					</p:selectOneMenu>
					<p:message for="idFuncao" />
					<h:outputText value=" " />

					<h:outputLabel value="Tipo de Animal:" styleClass="icoObrigatorio" />
					<p:selectOneMenu id="idTipoAnimal" effect="fade" style="width:300px;" value="#{animalBean.idTipoAnimal}"
						requiredMessage="#{animalBean.requiredMessage}" required="true">
						<f:selectItem itemLabel="Selecione" itemValue="" />
						<f:selectItems value="#{animalBean.listaTipoAnimal}" />
					</p:selectOneMenu>
					<p:message for="idTipoAnimal" />
					<h:outputText value=" " />


					<h:outputLabel value="Raça:" styleClass="icoObrigatorio" />
					<p:selectOneMenu id="idRaca" effect="fade" style="width:300px;" value="#{animalBean.idRaca}"
						requiredMessage="#{animalBean.requiredMessage}" required="true">
						<f:selectItem itemLabel="Selecione" itemValue="" />
						<f:selectItems value="#{animalBean.listaRacas}" />
					</p:selectOneMenu>
					<p:message for="idRaca" />
					<h:outputText value=" " />

					<h:outputLabel value="Grau de Sangue:" styleClass="icoObrigatorio" />
					<p:selectOneMenu id="idGrauSangue" effect="fade" style="width:300px;" value="#{animalBean.idGrauSangue}"
						requiredMessage="#{animalBean.requiredMessage}" required="true">
						<f:selectItem itemLabel="Selecione" itemValue="" />
						<f:selectItems value="#{animalBean.listaGrauSangue}" />
					</p:selectOneMenu>
					<p:message for="idGrauSangue" />
					<h:outputText value=" " />

					<h:outputLabel value="Tipo De Cobertura:" styleClass="icoObrigatorio" />
					<p:selectOneMenu id="idTpCobertura" effect="fade" style="width:300px;" value="#{animalBean.idTpCobertura}"
						requiredMessage="#{animalBean.requiredMessage}" required="true">
						<f:selectItem itemLabel="Selecione" itemValue="" />
						<f:selectItems value="#{animalBean.listaTipoCobertura}" />
					</p:selectOneMenu>
					<p:message for="idTpCobertura" />
					<h:outputText value=" " />

					<h:outputLabel value="Observação:" />
					<p:inputTextarea value="#{animalBean.model.observacao}" id="obs" cols="60" rows="6" autoResize="false" />
				</h:panelGrid>
			</p:fieldset>
			<br />
			<p:toolbar>
				<p:toolbarGroup align="left">
					<p:commandButton value="Voltar" immediate="true" ajax="false" action="pesquisarAnimal.jsf"
						rendered="#{animalBean.mostrarVoltar}" />
					<p:commandButton value="Limpar" immediate="true" ajax="false" action="animal.jsf" />
					<p:commandButton rendered="#{p:ifGranted('ROLE_ANIMAL_SALVAR')}" value="Salvar" ajax="true" process="@form"
						update="@form" action="#{animalBean.save}" />
				</p:toolbarGroup>
			</p:toolbar>
			<br />
		</h:form>
	</ui:define>
</ui:composition>